//
//  XKMainTabBarController.m
//  XKJY
//
//  Created by xuyaguang on 2017/1/10.
//  Copyright © 2017年 xiaokang100. All rights reserved.
//



#import "XKMainTabBarController.h"

#import "XKMainNavigationController.h"
#import "XKHomeViewController.h"
#import "XKTradeViewController.h"
#import "XKTradeController.h"
#import "XKNewsViewController.h"
#import "XKMineViewController.h"
#import "XKSupportController.h"

@interface XKMainTabBarController ()

@end

@implementation XKMainTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setAppearance];
    [self createChildControllers];
}

// 设置tabBarItem的文字颜色和字号
- (void)setAppearance {
    
    // 未选中字体颜色和字号
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:UIColorFromRGB(0xa9a9a9), NSFontAttributeName : Font(13)} forState:UIControlStateNormal];
    
    // 选中字体颜色和字号
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:UIColorFromRGB(0xFD5353), NSFontAttributeName : Font(13)} forState:UIControlStateSelected];
    
    // 设置文字的位置
    [[UITabBarItem appearance] setTitlePositionAdjustment:UIOffsetMake(0, -2)];
    
}

- (void)createChildControllers {
    
    [self addChildController:[XKHomeViewController new]
                       title:@"首页"
                  imageNamed:@"tabbar_home_normal"
                selImageName:@"tabbar_home_selected"];
    
    [self addChildController:[XKTradeController new]
                       title:@"市场"
                  imageNamed:@"tabbar_trade_normal"
                selImageName:@"tabbar_trade_selected"];
    
    [self addChildController:[XKNewsViewController new]
                       title:@"资讯"
                  imageNamed:@"tabbar_news_normal"
                selImageName:@"tabbar_news_selected"];
    
    [self addChildController:[XKMineViewController new]
                       title:@"我的"
                  imageNamed:@"tabbar_mine_normal"
                selImageName:@"tabbar_mine_selected"];
}

- (void)addChildController:(UIViewController *)childController title:(NSString *)title imageNamed:(NSString *)imageName selImageName:(NSString *)selImageName {
    
    childController.tabBarItem.title = title;
    childController.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childController.tabBarItem.selectedImage = [[UIImage imageNamed:selImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    // 设置tabbarItem图片的偏移位置
    [childController.tabBarItem setImageInsets:UIEdgeInsetsMake(-4*Scale_W, 0, 4*Scale_W, 0)];
    XKMainNavigationController *nav = [[XKMainNavigationController alloc] initWithRootViewController:childController];
    [self addChildViewController:nav];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
